const webpack = require('webpack'),
  path = require('path'),
  autoprefixer = require('autoprefixer'),
  HtmlWebpackPlugin = require('html-webpack-plugin'),
  ExtractTextPlugin = require('extract-text-webpack-plugin'),
  config = require('./const')

const webpackConfig = {

  // 页面入口文件配置
  entry: {
    app: [
      './dev'
    ]

      // Vendor: [
      //   'react',
      //   'react-dom',
      //   'react-router',
      //   'redux',
      //   'react-redux',
      //   'isomorphic-fetch'
      // ]
  },
  output: {
    path: path.join(__dirname, '..', config[process.env.NODE_ENV].path),
    filename: `${config[process.env.NODE_ENV].siteName}/src/js/[name].[hash:5].js`,
    chunkFilename: `${config[process.env.NODE_ENV].siteName}/src/js/[name].[hash:5].js`,
    publicPath: '/'
  },
  module: {

    // 加载器配置
    rules: [{
      test: /\.(jpg|png|gif|webp)$/,
      use: `url-loader?limit=8192&name=${config[process.env.NODE_ENV].siteName}/src/images/[name].[ext]`
    }, {
      test: /\.html$/,
      use: 'html-loader'
    }]
  },
  resolve: {extensions: ['.js', '.json', '.scss']},
  plugins: [
    new ExtractTextPlugin('[name].css'),
    new HtmlWebpackPlugin({
      filename: `./${config[process.env.NODE_ENV].siteName}/index.html`,
      template: './template/index.tpl.html'
    })

    // new webpack.LoaderOptionsPlugin({options: {postcss: [autoprefixer()]}})
  ]
}

module.exports = webpackConfig
